'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url admin/system/alioss/kh/alioss 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------
		console.log("data=", data);

		res.ishad = await db.collection('a_config').where({
			name: "alioss"
		}).get()

		if (res.ishad.data[0]) {
			// 存在该条记录则更新
			res.update = await db.collection('a_config').where({
				name: "alioss"
			}).update({
				region: data.region,
				accessKeyId: data.accessKeyId,
				accessKeySecret: data.accessKeySecret,
				bucket: data.bucket,
				baseurl: data.baseurl,
			})
		} else {
			//不存在该条记录则新增
			res.adds = await db.collection('a_config').add({
				name: "alioss",
				region: data.region,
				accessKeyId: data.accessKeyId,
				accessKeySecret: data.accessKeySecret,
				bucket: data.bucket,
				baseurl: data.baseurl,
			})
		}

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
